import Module from "./Module"
import { SetMouseCursorCommand } from "../command/cursor.command"
import EngineContext from "../EngineContext"
//鼠标状态
export default class MouseCursor extends Module {
  activeCursor: string
  config: any
  constructor() {
    super(...arguments)
    this.name = "mouse-cursor"
    this.activeCursor = null
  }
  async init(config, t: EngineContext) {
    this.config = Object.assign({ classPrefix: "cursor" }, config)
    this.bindings.push(t.commandBinder.addBinding(SetMouseCursorCommand, async e => this.changeCursor(e.cursor)))
  }
  changeCursor(e: string) {
    const { container, classPrefix } = this.config
    if (e !== this.activeCursor) {
      this.activeCursor && container.classList.remove(`${classPrefix}-${this.activeCursor}`)
      e && container.classList.add(`${classPrefix}-${e}`)
      this.activeCursor = e
    }
  }
}
